home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000093_icon-group-sender _Thu Apr 8 16:28:46 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  1KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA22603
  4.     for icon-group-addresses; Thu, 8 Apr 1999 16:27:34 -0700 (MST)
  5. Message-Id: <199904082327.QAA22603@baskerville.CS.Arizona.EDU>
  6. To: icon-group@optima.CS.Arizona.EDU
  7. Date: Thu, 08 Apr 1999 17:35:22 -0400
  8. From: "Hudon, Christian (EXCHANGE:MTL:6X16)" <chudon@americasm01.nt.com>
  9. Subject: Deep copy in Icon?
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13. Hi,
  14.  
  15. could someone tell me what's wrong with the following snippet of Icon
  16. code?
  17.  
  18. procedure deepcopy(x, t)
  19.     /t := table()
  20.     case type(x) of {
  21.         "list"|"table"|"set"|"record" : {
  22.             e := t[image(x)]
  23.             if /e then {
  24.                 e := copy(x)
  25.                 t[image(x)] := e
  26.                 every sub := !e do sub := deepcopy(sub, t)
  27.                 }
  28.         return e
  29.         }
  30.        default: return x
  31.     }
  32. end
  33.  
  34. (This is supposed to do a deep copy of an arbitrary object, preserving
  35. the structure.)
  36.  
  37. I thought you could assign to the elements of a set, list, etc. with
  38. something like
  39.  
  40.   every e := !l do e := foo(e)
  41.  
  42. but it doesn't seem to work here... when I do deepcopy([1, [2, 3], 4]),
  43. the list that's returned still has the inner list [2, 3] shared.
  44.  
  45. If there's a more Icon-ish way to do all this, I'm also appreciate
  46. hearing about it.
  47.  
  48. Thanks,
  49.  
  50.   Christian
  51.  
  52.  
  53.  
  54.  
  55.  
  56.